package com.ruoyi.mq.service.serviceImpl;

import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.mq.service.MessageProcessor;
import com.ruoyi.system.domain.GwHomeSummarize;
import com.ruoyi.system.service.IGwHomeSummarizeService;
import org.apache.logging.log4j.util.Strings;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.stereotype.Component;

import java.util.Map;

@Component
public class MessageProcessorContext {
    @Autowired
    private IGwHomeSummarizeService gwHomeSummarizeService;
    @Autowired
    private Map<String, MessageProcessor> messageProcessors;
    @Autowired
    private SimpMessagingTemplate messagingTemplate;
    public void processMessage(JSONObject message) {
        String strategy = message.getString("strategy");
        MessageProcessor processor = messageProcessors.get(strategy);
        if (processor == null) {
            System.out.println("请输入合法strategy值");
            return;
        }
        processor.processMessage(message);

        //首页数据展示
        if ("codeVolumeProcessor".equals(strategy)||"parseVolumeProcessor".equals(strategy)||"productInfoProcessor".equals(strategy)||"companyInfoProcessor".equals(strategy)){
            GwHomeSummarize gwHomeSummarize = gwHomeSummarizeService.selectGwHomeSummarizeAll(null);


            messagingTemplate.convertAndSend("/topic/updates", gwHomeSummarize);
        }


    }
}
